package com.bby.disk.manager.tempfile;

import com.bby.common.config.GlobalSettings;
import org.springframework.stereotype.Component;

import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.spi.InitialContextFactory;
import java.io.File;
import java.util.Hashtable;

/**
 * 管理临时文件，临时文件：<br>
 * 临时文件每天定时清理，根据LastModified<br>
 * 临时文件每次试用后都会刷新（LastModified）<br>
 * 临时文件生存时间在配置文件中定义<br>
 */
@Component
public class TempFileManager implements InitialContextFactory {
    static String ROOT = GlobalSettings.TEMP_FILES_DIR+File.separator+"video-img";

    static {
        new File(ROOT).mkdirs();
    }
    public static File createVideoImgFile(String id){
        File file = new File(ROOT,id+".png");
        if (file.exists()){
            file.setLastModified(System.currentTimeMillis());
        }
        return file;
    }


    @Override
    public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
        return null;
    }
}
